﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL.Admin;
using SqlSugar;
using DAL;

namespace BLL
{
    public abstract class BaseServicePro<M>
        where M : class,new()
    {
        protected abstract BaseDaoPro<M> GetDao();

        public virtual bool Delete(int[] ids)
        {
            return GetDao().Delete(ids);
        }

        public virtual List<M> GetList(string searchJson, ref int totalCount, int pageIndex = 1, int pageSize = 15)
        {
            List<IConditionalModel> searchParams = DAL.Utils.SqlUtils.JsonToConditionalModels(searchJson);
            return GetDao().QueryForList(searchParams, ref totalCount, pageIndex, pageSize);
        }

        public virtual List<M> GetList(string searchJson, string orderBy, ref int totalCount, int pageIndex = 1, int pageSize = 15)
        {
            List<IConditionalModel> searchParams = DAL.Utils.SqlUtils.JsonToConditionalModels(searchJson);
            return GetDao().QueryForList(searchParams, orderBy, ref totalCount, pageIndex, pageSize);
        }

        public virtual M GetOne(string searchJson)
        {
            List<IConditionalModel> searchParams = DAL.Utils.SqlUtils.JsonToConditionalModels(searchJson);

            return GetDao().QueryForOne(searchParams);
        }

        public virtual bool Save(M model)
        {
            return GetDao().Insert(model);
        }

        public virtual bool Update(M model)
        {
            return GetDao().Insert(model);
        }
    }
}
